File: /var/www/kevin-demo/wp-content/plugins/allspice/includes/cron.php
<?php
// includes/cron.php
if (!defined('ABSPATH')) exit;
define('ALLSPICE_CRON_HOOK', 'allspice_cron_sync');
function allspice_cron_schedules($schedules): array {
if (!isset($schedules['allspice_12h'])) $schedules['allspice_12h'] = array('interval' => 12 * HOUR_IN_SECONDS, 'display' => 'Allspice (12 hours)');
return $schedules;
}
add_filter('cron_schedules', 'allspice_cron_schedules');
function allspice_activate_plugin(): void {
if (!wp_next_scheduled(ALLSPICE_CRON_HOOK)) wp_schedule_event(time() + 300, 'allspice_12h', ALLSPICE_CRON_HOOK);
/* Fresh installs start on the RECOMMENDED styles: Floating (desktop) / Inline (mobile).
Only when no settings row exists at all - an existing site keeps whatever it runs,
because flipping a live site's reader experience on a plugin update is not our call.
(Sites that saved settings before these keys existed also keep their legacy-mapped
behavior via allspice_get_widget_style's fallback chain.) */
if (get_option(ALLSPICE_SETTINGS_OPTION) === false) {
add_option(ALLSPICE_SETTINGS_OPTION, array(
'widget_style_desktop' => 'floating',
'widget_style_mobile' => 'inline',
));
}
}
function allspice_deactivate_plugin(): void {
$t = wp_next_scheduled(ALLSPICE_CRON_HOOK);
if ($t) wp_unschedule_event($t, ALLSPICE_CRON_HOOK);
}
function allspice_cron_refresh(): void {
$rb = allspice_refresh_buttons_cache(false);
if (empty($rb['ok'])) {
allspice_opt_update(array('cache_last_error' => (string)($rb['error'] ?? 'Unknown error')));
}
$rr = allspice_refresh_recipes_cache(false);
if (empty($rr['ok'])) {
allspice_opt_update(array('recipes_last_error' => (string)($rr['error'] ?? 'Unknown error')));
}
$rtp = allspice_refresh_theme_policies_cache(false);
if (empty($rtp['ok'])) {
allspice_opt_update(['theme_policies_last_error' => (string)($rtp['error'] ?? 'Unknown error')]);
}
/* Content-access rules (whole-post gates). Failure preserves the prior snapshot. */
if (function_exists('allspice_refresh_content_gates')) {
allspice_refresh_content_gates(false);
}
}
add_action(ALLSPICE_CRON_HOOK, 'allspice_cron_refresh');